/*	Copyright 2007 - Xavier Baro (xbaro@cvc.uab.cat)

	This file is part of eapmlib.

    Eapmlib is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 3 of the License, or any 
	later version.

    Eapmlib is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __INTSAMPLESSET_H__
#define __INTSAMPLESSET_H__

#include "EvolutiveLib.h"
#include "SamplesSet.h"

using namespace std;
namespace Evolutive {

	class EVOLUTIVELIB_API CIntSamplesSet: public CSamplesSet
	{
		//! Methods
	public:
		//! Default constructor		
		CIntSamplesSet(void);
		
		//! Default destructor
		virtual ~CIntSamplesSet(void);

#ifdef USE_OPENCV
		//! Calculate the integral images
		void CalcIntImages(bool UseRotated=false);

		//! Returns a pointer to the integral image
		IplImage* GetIntImage(unsigned int Idx);

		//! Returns a pointer to the rotated integral image
		IplImage* GetRIntImage(unsigned int Idx);

		//! Operators overload
		virtual CData* operator[] (unsigned int Idx);

		//! Returns a pointer to a data structure
		virtual CData* GetData(unsigned int Idx);

		//! Split the data into train and test
		virtual void SplitData(CIntSamplesSet *Train,CIntSamplesSet *Test,double TestPer);

		//! Create a sample set by adding to existing samples set
		virtual void MergeData(CIntSamplesSet *Samples1,CIntSamplesSet *Samples2);

		//! Calculate the normalization factor using the fast lighting correction algorithm
		virtual double GetNormFactor(unsigned int Idx);

		//! Change the well classified negative samples (from base class)
		virtual void UpdateSamples(CClassifier *Classifier);
	
	protected:			
		//! Save or recover the data to/from a file (from base class)
		virtual void Serialize(std::fstream &fs,bool Saving);

		//! Initialize the integral images data
		void InitializeIntegralData(void);

		//! Copy the value parameters and allocate the dynamic data (from base class)
		virtual void CopyParameters(CSamplesSet *Object,int NumSamples);

#endif //USE_OPENCV	

		//! Attributes
	protected:

		//! Matrix with all the integral images by columns
		unsigned char *m_IntSamplesSet;

		//! Matrix with all the rotated integral images by columns
		unsigned char *m_RIntSamplesSet;

		//! Matrix with all the squared integral images by columns
		unsigned char *m_SqIntSamplesSet;
		
		//! Flag that indicates when the the integral information is contained
		bool m_HasIntInformation;

		//! Flag that indicates when the the rotated integral information is contained
		bool m_HasRotatedIntInformation;

		//! Size of the integral images
		CvSize m_IntImgSize;
		
		//! Depth of the integral images
		int m_IntImgDepth;

		//! Depth of the squared sum integral images
		int m_SqIntImgDepth;
		
		//! Number of positions for each integral image (channels, size, ...)		
		int m_IntDataLen;

		//! Number of positions for each squared sum integral image (channels, size, ...)		
		int m_SqIntDataLen;
	};	
}

#endif // __INTSAMPLESSET_H__
